/*
 * I2cInterface.h
 *
 *  Created on: 2021-07-25
 *      Author: vicent-PC
 */

#ifndef MAIN_I2C_I2CINTERFACE_H_
#define MAIN_I2C_I2CINTERFACE_H_

#include <stdint.h>

#include "driver/gpio.h"
#include "driver/i2c.h"
#include "esp_err.h"
#include "esp_log.h"
#include "esp_system.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

class I2cInterface {
   public:
    I2cInterface();
    virtual ~I2cInterface();
    esp_err_t i2c_probe(i2c_port_t i2c_num, uint8_t slave_addr,
                        uint16_t *reg_val);
    void i2c_master_init();
    void I2cScanner();
    void stressTest(uint8_t i2c_addr, uint16_t loop_cnt);
    int I2cScannerAddr();

    I2cInterface(uint8_t i2cAddr);
    void regScanner();
    int16_t readRegister16(uint8_t reg);
    int readRegN(uint8_t reg0, uint8_t reg1, uint8_t* data, size_t size, void* cb = nullptr);

    int writeRegister16(uint8_t reg, uint16_t val);
    uint8_t readRegister8(uint8_t reg);
    int writeRegister8(uint8_t reg, uint8_t val);

   private:
    uint8_t mI2cAddr = 0;
    int m_i2c_port_id = 0;
};

#endif /* MAIN_I2C_I2CINTERFACE_H_ */
